// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ManipulatorStatus.cs" company="Microsoft Corporation">
// The MIT License (MIT)
// 
// Copyright (c) 2014, Microsoft Corporation
// 
// Permission is hereby granted, free of charge, to any person obtaining a copy
//  of this software and associated documentation files (the "Software"), to deal
//  in the Software without restriction, including without limitation the rights
//  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//  copies of the Software, and to permit persons to whom the Software is
//  furnished to do so, subject to the following conditions:
// 
// The above copyright notice and this permission notice shall be included in
//  all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//  THE SOFTWARE.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace Microsoft.Robotics.Manipulation
{
    using System;
    using System.Runtime.Serialization;
    using Microsoft.Robotics.Numerics;

    /// <summary>
    /// Arm manipulation status message - defines current arm configuration such as
    /// End effector position, joint configuration
    /// </summary>
    [DataContract]
    public class ManipulatorStatus 
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="ManipulatorStatus" /> class
        /// This message reports the configuration of the arm
        /// </summary>
        /// <param name="timeStamp">Hardware timestamp</param>
        /// <param name="tcpCartesianPosition">Cartesian coordinates of the tcp in base frame</param>
        /// <param name="tcpCommandedCartesianPosition">Last commanded tcp cartesian position in base frame </param>
        /// <param name="jointPositions">Joint positions</param>
        /// <param name="jointVelocities">Joint velocities.</param>
        /// <param name="commandedJointPositions">Last commanded joint positions</param>
        /// <param name="jointTorque">Joint torques</param>
        /// <param name="externalJointTorque">Joint Torques from external forces</param>
        /// <param name="tcpExternalForceTorque">Estimated tool control point forces and torques</param>
        /// <param name="tcpUnexpectedForceOccured"> Indicates if unexpected force has occurred at TCP. </param>
        /// <param name="tcpUnexpectedForceTorque"> Indicates the unexpected force-torque vector (null if none detected). </param>
        public ManipulatorStatus(
            double timeStamp,
            Pose tcpCartesianPosition,
            Pose tcpCommandedCartesianPosition,
            double[] jointPositions,
            double[] jointVelocities,
            double[] commandedJointPositions,
            double[] jointTorque,
            double[] externalJointTorque,
            double[] tcpExternalForceTorque,
            bool tcpUnexpectedForceOccured = false,
            double[] tcpUnexpectedForceTorque = null)
        {
            this.TcpCartesianPosition = tcpCartesianPosition;
            this.TcpCommandedCartesianPosition = tcpCommandedCartesianPosition;
            this.JointPositions = jointPositions;
            this.JointVelocities = jointVelocities;
            this.CommandedJointPositions = commandedJointPositions;
            this.JointTorque = jointTorque;
            this.ExternalJointTorque = externalJointTorque;
            this.TcpForceTorque = tcpExternalForceTorque;
            this.TcpUnexpectedForceOccured = tcpUnexpectedForceOccured;
            this.TcpUnexpectedForceTorque = tcpUnexpectedForceTorque;
            this.TimeStampinMS = timeStamp;
        }

        /// <summary>
        /// Gets the hardware timestamp in millisecond
        /// </summary>
        [DataMember]
        public double TimeStampinMS { get; private set; }

        /// <summary>
        /// Gets the cartesian position of the arm end effector
        /// </summary>
        [DataMember]
        public Pose TcpCartesianPosition { get; private set; }

        /// <summary>
        /// Gets the commanded cartesian position of the arm end effector
        /// </summary>
        [DataMember]
        public Pose TcpCommandedCartesianPosition { get; private set; }

        /// <summary>
        /// Gets the position of the arm joints. 
        /// Dimension is equal to the number of arm joints
        /// </summary>
        [DataMember]
        public double[] JointPositions { get; private set; }

        /// <summary>
        /// Gets the velocities of the arm joints. 
        /// Dimension is equal to the number of arm joints
        /// </summary>
        [DataMember]
        public double[] JointVelocities { get; private set; }

        /// <summary>
        /// Gets the commanded position of the arm joints. 
        /// Dimension is equal to the number of arm joints
        /// </summary>
        [DataMember]
        public double[] CommandedJointPositions { get; private set; }

        /// <summary>
        /// Gets the torque at each joint
        /// Dimension is equal to the number of arm joints
        /// </summary>
        [DataMember]
        public double[] JointTorque { get; private set; }

        /// <summary>
        /// Gets the estimated torque at each joint due to external forces
        /// Dimension is equal to the number of arm joints
        /// </summary>
        [DataMember]
        public double[] ExternalJointTorque { get; private set; }

        /// <summary>
        /// Gets estimated torque applied to the tool control point
        /// in 6 dimensional coordinates
        /// </summary>
        [DataMember]
        public double[] TcpForceTorque { get; private set; }

        /// <summary>
        /// Gets a value indicating whether an unexpected force has been detected at the TCP.
        /// Definition of unexpected force is controller dependant.
        /// </summary>
        [DataMember]
        public bool TcpUnexpectedForceOccured { get; private set; }

        /// <summary>
        /// Gets the force torque reading that caused the controller to indicate
        /// an unexpected force.  Null if no unexpected force-torque has occurred.
        /// </summary>
        [DataMember]
        public double[] TcpUnexpectedForceTorque { get; private set; }
    }
}
